#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

layout(points) in;
//layout(triangle_strip, max_vertices=128) out;
layout(line_strip, max_vertices=64) out;
//layout(points, max_vertices=64) out;


#include "../../../../core/shader_taster_transform.h"






//====================== 顶点阶段输入数据 =====================
in gl_PerVertex {
	float gl_PointSize;
} gl_in[];

layout(location = 1) in VS_GS_VERTEX {
	vec4 Position;
	vec3 vCubeSize;
	uint vInstance;
}vertex_in[];


//======================= 几何阶段输出数据 ========================
layout(location = 0) out vec4 gColor;





void main(void){
	// 位置  大小  对齐方式  深度
	mat4 mat = mat_Model[vertex_in[0].vInstance];
	//摄像机逆矩阵
	//mat4 mr = transpose(mat_ProjecView[1]);

	vec4 pos = vertex_in[0].Position;
	vec3 size = vertex_in[0].vCubeSize;
	//size = vec4(3,3,3,1);
	float BoxSize = 0.5;
	


	vec4 v = pos;
	v.xyz -= size.xyz * 0.5f;
	gl_Position = mat_ProjecView[0] * mat * v;
	gl_PointSize = 1;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.x += size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gl_PointSize = 1;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	
	v.z += size.z;
	gl_Position = mat_ProjecView[0] * mat * v;
	gl_PointSize = 1;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.x -= size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gl_PointSize = 1;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.z -= size.z;
	gl_Position = mat_ProjecView[0] * mat * v;
	gl_PointSize = 1;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();



	v = pos;
	v.xyz += size.xyz * 0.5f;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.z -= size.z;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.x -= size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.z += size.z;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.x += size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();







	v = pos;
	v.xyz -= size.xyz * 0.5f;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.y += size.y;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();


	v.x += size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();

	v.y -= size.y;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();


	v.z += size.z;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	
	v.y += size.y;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();


	v.x -= size.x;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	
	v.y -= size.y;
	gl_Position = mat_ProjecView[0] * mat * v;
	gColor = vec4(0.5f, 0.5f, 0.5f, 1.0f);
	EmitVertex();
	EndPrimitive();

}



 